#
# "@(#) $Id: tatusImporterProgressView.py,v 1.1.1.1 2006-07-27 03:16:08 gioshe Exp $"
#
# This work is released under the GNU GPL, version 2 or later.
#
from Utils.kdeemul import *
from Utils.human import *
from StatusProgressBar import *
from CD.Importer import *
from PixmapPushButton import *
from Utils.Paths import *
from Utils.utils import *

class StatusImporterProgressView(QWidget):
	def __init__(self,container,statusView):
		global _backColor
		QWidget.__init__(self,container)
		self.statusView = statusView
		backColor=QColor(Settings.settings().get('ColorR'),Settings.settings().get('ColorG'),Settings.settings().get('ColorB'))
		self.setPaletteBackgroundColor(backColor)
		self.buildViews()
		QObject.connect(Importer.singleton(),PYSIGNAL("status"),self.progress)
	
	def buildViews(self):
		#f = QFont("fixed",6)
		hlayout = QHBoxLayout(self)
		hlayout.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		vlayout = QVBoxLayout()
		vlayout.setSpacing(-5)
		hlayout.addLayout(vlayout,100)
		#vlayout.addItem(QSpacerItem(1,1,QSizePolicy.Fixed,QSizePolicy.Expanding))
		#self.title = QLabel(i18n("Song Name"),self)
		self.title = KSqueezedTextLabel(self)
		self.title.setText("Song Name")
		#self.title.setFont(f)
		self.title.setAlignment(Qt.AlignCenter)
		vlayout.addWidget(self.title)
		self.elapsed = QLabel(i18n("Completion"),self)
		#self.elapsed.setFont(f)
		self.elapsed.setAlignment(Qt.AlignCenter)
		vlayout.addWidget(self.elapsed)
		playout = QHBoxLayout()
		vlayout.addLayout(playout)
		playout.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		self.progressView = StatusProgressBar(self)
		playout.addWidget(self.progressView,100)
		playout.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		#vlayout.addItem(QSpacerItem(1,1,QSizePolicy.Fixed,QSizePolicy.Expanding))
		hlayout.addItem(QSpacerItem(1,1,QSizePolicy.Expanding,QSizePolicy.Fixed))
		cancelIcon = QIconSet(QPixmap(art("buttonstatuscancel.png")))
		self.cancelButton = SmallPixmapPushButton(cancelIcon,"",self)
		QToolTip.add(self.cancelButton,i18n("Cancel the current import"))
		QObject.connect(self.cancelButton,SIGNAL("clicked()"),self.cancelImport)
		hlayout.addWidget(self.cancelButton)
		
	def progress(self,status):
		#print "status view got progress"
		self.progressView.progress(status)
		state = status['Status']
		if state=='Begin':
			self.title.setText(i18n("Preparing Import"))
			self.elapsed.setText('')
			self.statusView.showStatus(self)
		elif state=='Importing':
			self.title.setText("%s: %s" % (state,status['Filename']))
			self.elapsed.setText(unikode(i18n("%d of %d")) % (status['currentTime']+1,status['totalTime']))
		elif state=='End':
			self.statusView.hideStatus(self)

	def cancelImport(self):
		Importer.killCurrentImporter()
